/******************************************************************************

  Copyright (C), 2014-2016, Hisilicon Tech. Co., Ltd.

 ******************************************************************************
  File Name     : drv_hdmi_common.c
  Version       : Initial Draft
  Author        : Hisilicon multimedia software group
  Created       : 2015/08/10
  Description   :
  History       :
  Date          : 2015/08/10
  Author        : 
  Modification  :
*******************************************************************************/
#include "drv_hdmi_common.h"
#include "drv_hdmi_infoframe.h"
#ifdef HDMI_BUILD_IN_BOOT
#include "boot_hdmi_intf.h"
#else
#include <linux/delay.h>
#include "drv_hdmi_platform.h"
#endif


#define CHECK_MAX_VALUE(out, in, max)    out = (HI_U32)(((in) > (max))? (max): (in))

HDMI_VIDEO_DEF_S s_stCEA861FVideoCodesDes[CEA861FVideoCodesMax] =
{
    {0,                     	0,      0,  0,      0,      HDMI_PICTURE_ASPECT_NONE, HDMI_VIDEO_TIMING_UNKNOWN,          HDMI_VIDEO_UNKNOWN,     	(HI_U8 *)"NONE"},
    {HDMI_640X480P60_4_3,   	25175,  60, 640,    480,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_640X480P_60000,   HDMI_VIDEO_PROGRESSIVE, 	(HI_U8 *)"640*480p60 4:3"},
    {HDMI_720X480P60_4_3,   	27000,  60, 720,    480,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X480P_60000,   HDMI_VIDEO_PROGRESSIVE, 	(HI_U8 *)"720*480p60 4:3"},
    {HDMI_720X480P60_16_9,		27000,	60,	720,    480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X480P_60000,   HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*480p60 16:9"},
    {HDMI_1280X720P60_16_9,		74250,	60,	1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p60 16:9"},
    {HDMI_1920X1080I60_16_9, 	74250,	60,	1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080I_60000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1920*1080i60 16:9"},
    {HDMI_1440X480I60_4_3,		27000,	60,	1440,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X480I_60000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*480i60 4:3"},
    {HDMI_1440X480I60_16_9,		27000,	60,	1440,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X480I_60000,  HDMI_VIDEO_INTERLACE,     (HI_U8 *)"1440*480i60 16:9"},
    {HDMI_1440X240P60_4_3,		27000,	60,	1440,	240,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X240P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*240p60 4:3"},
    {HDMI_1440X240P60_16_9, 	27000,	60,	1440,	240,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X240P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*240p60 16:9"},
    {HDMI_2880X480I60_4_3,		54000,	60,	2880,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X480I_60000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"2880*480i60 4:3"},
    {HDMI_2880X480I60_16_9,		54000,	60,	2880,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X480I_60000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"2880*480i60 16:9"},
    {HDMI_2880X240P60_4_3,		54000,	60, 2880,	240,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X240I_60000,  HDMI_VIDEO_PROGRESSIVE,  	(HI_U8 *)"2880*240i60 4:3"},
    {HDMI_2880X240P60_16_9,     54000,	60, 2880,	240,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X240I_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*240i60 16:9"},
    {HDMI_1440X480P60_4_3,		54000,	60, 1440,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X480P_60000,  HDMI_VIDEO_PROGRESSIVE,   (HI_U8 *)"1440*480p60 4:3"},
    {HDMI_1440X480P60_16_9,     54000,	60, 1440,	480,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X480P_60000,  HDMI_VIDEO_PROGRESSIVE,   (HI_U8 *)"1440*480p60 16:9"},
    {HDMI_1920X1080P60_16_9,    148500,	60,	1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_60000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p60 16:9"},
    {HDMI_720X576P50_4_3,		27000,	50,	720,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X576P_50000,	  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p50 4:3"},
    {HDMI_720X576P50_16_9,		27000,	50,	720,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X576P_50000,	  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p50 16:9"},
    {HDMI_1280X720P50_16_9,		74250,	50,	1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p50 16:9"},
    {HDMI_1920X1080I50_16_9,	74250,	50, 1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080I_50000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1920*1080i50 16:9"},
    {HDMI_1440X576I50_4_3,		27000,	50, 1440,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X576I_50000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i50 4:3"},
    {HDMI_1440X576I50_16_9,		27000,	50, 1440,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X576I_50000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i50 16:9"},
    {HDMI_1440X288P50_4_3,		27000,	50, 1440,	288,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X288P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*288p50 4:3"},
    {HDMI_1440X288P50_16_9,     27000,	50, 1440,	288,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X288P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*288p50 16:9"},
    {HDMI_2880X576I50_4_3,		54000,	50,	2880,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X576I_50000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"2880*576i50 4:3"},
    {HDMI_2880X576I50_16_9,		54000,	50, 2880,	576,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X576I_50000,  HDMI_VIDEO_INTERLACE,		(HI_U8 *)"2880*576i50 16:9"},
    {HDMI_2880X288P50_4_3,		54000,	50, 2880,	288,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X288P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*288p50 4:3"},
    {HDMI_2880X288P50_16_9,		54000,	50, 2880,	288,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X288P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*288p50 16:9"},
    {HDMI_1440X576P50_4_3,		54000,	50, 1440,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X576P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*576p50 4:3"},
    {HDMI_1440X576P50_16_9,     54000,	50, 1440,	576, 	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X576P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1440*576p50 16:9"},
    {HDMI_1920X1080P50_16_9, 	148500,	50, 1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_50000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p50 16:9"},
    {HDMI_1920X1080P24_16_9,	742500,	24, 1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_24000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p24 16:9"},
    {HDMI_1920X1080P25_16_9,	742500,	25, 1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_25000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p25 16:9"},
    {HDMI_1920X1080P30_16_9,	742500,	30, 1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_30000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p30 16:9"},
    {HDMI_2880X480P60_4_3,		108000,	60,	2880,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X480P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*480p60 4:3"},
    {HDMI_2880X480P60_16_9,		108000,	60,	2880,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X480P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*480p60 16:9"},
    {HDMI_2880X576P50_4_3,		108000,	50,	2880,	576, 	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_2880X576P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*576p50 4:3"},
    {HDMI_2880X576P50_16_9,     108000,	50,	2880,	576,    HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_2880X576P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2880*576p50 16:9"},
    {HDMI_1920X1080I50_16_9_1250,72000,	50,	1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080I_50000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1920*1080i50 16:9"},
    {HDMI_1920X1080I100_16_9,	148500,	100,1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080I_100000,HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1920*1080i100 16:9"},
    {HDMI_1280X720P100_16_9,	148500,	100,1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_100000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p100 16:9"},
    {HDMI_720X576P100_4_3,		54000,	100,720,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X576P_100000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p100 4:3"},
    {HDMI_720X576P100_16_9,		54000,	100,720,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X576P_100000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p100 16:9"},
    {HDMI_1440X576I100_4_3,		54000,	100,1440,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X576I_100000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i100 4:3"},
    {HDMI_1440X576I100_16_9,	54000,	100,1440,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X576I_100000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i100 16:9"},
    {HDMI_1920X1080I120_16_9,	148500,	120,1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080I_120000,HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1920*1080i120 16:9"},
    {HDMI_1280X720P120_16_9,	148500,	120,1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_120000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p120 16:9"},
	{HDMI_720X480P120_4_3,		54000,	120,720,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X480P_120000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*480p120 4:3"},
    {HDMI_720X480P120_16_9,		54000,	120,720,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X480P_120000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*480p120 16:9"},
    {HDMI_1440X480I120_4_3,		54000,	120,1440,	480,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X480I_120000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*480i120 4:3"},
    {HDMI_1440X480I120_16_9,	54000,	120,1440,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X480I_120000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*480i120 16:9"},
    {HDMI_720X576P200_4_3,		108000,	200,720,	576,	HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X576P_200000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p200 4:3"},
    {HDMI_720X576P200_16_9,		108000,	200,720,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X576P_200000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*576p200 16:9"},
    {HDMI_1440X576I200_4_3,		108000,	200,1440,	576,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X576I_200000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i200 4:3"},
    {HDMI_1440X576I200_16_9,	108000,	200,1440,	576,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X576I_200000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*576i200 16:9"},
    {HDMI_720X480P240_4_3,		108000,	240,720,	480,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_720X480P_240000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*480p240 4:3"},
    {HDMI_720X480P240_16_9,		108000,	240,720,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_720X480P_240000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"720*480p240 16:9"},
    {HDMI_1440X480I240_4_3,		108000,	240,1440,	480,    HDMI_PICTURE_ASPECT_4_3,  HDMI_VIDEO_TIMING_1440X480I_240000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*480i240 4:3"},
    {HDMI_1440X480I240_16_9,	108000,	240,1440,	480,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1440X480I_240000, HDMI_VIDEO_INTERLACE,		(HI_U8 *)"1440*480i240 16:9"},
    {HDMI_1280X720P24_16_9,		59400,	24,	1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_24000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p24 16:9"},
    {HDMI_1280X720P25_16_9,		74250,	25,	1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_25000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p25 16:9"},
    {HDMI_1280X720P30_16_9,		74250,	30, 1280,	720,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1280X720P_30000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p30 16:9"},
    {HDMI_1920X1080P120_16_9,	297000,	120,1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_120000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p120 16:9"},
    {HDMI_1920X1080P100_16_9,	297000,	100,1920,	1080,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_1920X1080P_100000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p100 16:9"},
    {HDMI_1280X720P24_64_27,	59400,	24,	1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_24000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p24 64:27"},
    {HDMI_1280X720P25_64_27,	74250,	25, 1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_25000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p25 64:27"},
    {HDMI_1280X720P30_64_27,	74250,	30,	1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_30000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p30 64:27"},
    {HDMI_1280X720P50_64_27,	74250,	50,	1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p50 64:27"},
    {HDMI_1280X720P60_64_27,	74250,	60,	1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p60 64:27"},
    {HDMI_1280X720P100_64_27,   148500,	100,1280,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_100000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p100 64:27"},
    {HDMI_1280X720P120_64_27,   148500,	120,1280,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1280X720P_120000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1280*720p120 64:27"},
    {HDMI_1920X1080P24_64_27,   74250,	24,	1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_24000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p24 64:27"},
    {HDMI_1920X1080P25_64_27,   74250,	25,	1920,	1080,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_25000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p25 64:27"},
    {HDMI_1920X1080P30_64_27,   74250,	30,	1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_30000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p30 64:27"},
    {HDMI_1920X1080P50_64_27,   148500,	50,	1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_50000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p50 64:27"},
    {HDMI_1920X1080P60_64_27,   148500,	60,	1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_60000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p60 64:27"},
    {HDMI_1920X1080P100_64_27,  297000,	100,1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_100000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p100 64:27"},
    {HDMI_1920X1080P120_64_27,	297000,	120,1920,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1920X1080P_120000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1920*1080p120 64:27"},
    {HDMI_1680X720P24_64_27,	59400,	24,	1680,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_24000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p24 64:27"},
    {HDMI_1680X720P25_64_27,	59400,	25,	1680,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_25000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p25 64:27"},
    {HDMI_1680X720P30_64_27,	59400,	30,	1680,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_30000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p30 64:27"},
    {HDMI_1680X720P50_64_27,	82500,	50,	1680,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_50000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p50 64:27"},
    {HDMI_1680X720P60_64_27,	99000,	60,	1680,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_60000,  HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p60 64:27"},
    {HDMI_1680X720P100_64_27,	165000,	100,1680,	720,    HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_100000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p100 64:27"},
    {HDMI_1680X720P120_64_27,	198000,	120,1680,	720,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_1680X720P_120000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"1680*720p120 64:27"},
    {HDMI_2560X1080P24_64_27,	99000,	24,	2560,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_24000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p24 64:27"},
    {HDMI_2560X1080P25_64_27,	99000,	25,	2560,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_25000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p25 64:27"},
    {HDMI_2560X1080P30_64_27,	118800,	30,	2560,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_30000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p30 64:27"},
    {HDMI_2560X1080P50_64_27,	185625,	50,	2560,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_50000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p50 64:27"},
    {HDMI_2560X1080P60_64_27,	198000,	60,	2560,	1080,   HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_60000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p60 64:27"},
    {HDMI_2560X1080P100_64_27,	371250,	100,2560,	1080,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_100000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p100 64:27"},
    {HDMI_2560X1080P120_64_27,	495000,	120,2560,	1080,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_2560X1080P_120000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"2560*1080p120 64:27"},
    {HDMI_3840X2160P24_16_9,	297000,	24,	3840,	2160,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_24000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p24 16:9"},
    {HDMI_3840X2160P25_16_9,	297000,	25,	3840,	2160,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_25000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p25 16:9"},
    {HDMI_3840X2160P30_16_9,	297000,	30,	3840,	2160,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_30000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p30 16:9"},
    {HDMI_3840X2160P50_16_9,	594000,	50,	3840,	2160,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_50000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p50 16:9"},
    {HDMI_3840X2160P60_16_9,	594000,	60,	3840,	2160,	HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_60000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p60 16:9"},
    {HDMI_4096X2160P24_256_135,	297000,	24,	4096,	2160,	HDMI_PICTURE_ASPECT_256_135,HDMI_VIDEO_TIMING_4096X2160P_24000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"4096*2160p24 256:135"},
    {HDMI_4096X2160P25_256_135,	297000,	25,	4096,	2160,	HDMI_PICTURE_ASPECT_256_135,HDMI_VIDEO_TIMING_4096X2160P_25000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"4096*2160p25 256:135"},
    {HDMI_4096X2160P30_256_135,	297000,	30,	4096,	2160,	HDMI_PICTURE_ASPECT_256_135,HDMI_VIDEO_TIMING_4096X2160P_30000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"4096*2160p30 256:135"},
    {HDMI_4096X2160P50_256_135,	594000,	50,	4096,	2160,	HDMI_PICTURE_ASPECT_256_135,HDMI_VIDEO_TIMING_4096X2160P_50000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"4096*2160p50 256:135"},
    {HDMI_4096X2160P60_256_135,	594000,	60,	4096,	2160,	HDMI_PICTURE_ASPECT_256_135,HDMI_VIDEO_TIMING_4096X2160P_60000,HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"4096*2160p60 256:135"},
    {HDMI_3840X2160P24_64_27,	297000,	24,	3840,	2160,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_3840X2160P_24000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p24 64:27"},
    {HDMI_3840X2160P25_64_27,	297000,	25,	3840,	2160,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_3840X2160P_25000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p25 64:27"},
    {HDMI_3840X2160P30_64_27,	297000,	30,	3840,	2160,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_3840X2160P_30000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p30 64:27"},
    {HDMI_3840X2160P50_64_27,	594000,	50,	3840,	2160,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_3840X2160P_50000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p50 64:27"},
    {HDMI_3840X2160P60_64_27,	594000,	60,	3840,	2160,	HDMI_PICTURE_ASPECT_64_27,HDMI_VIDEO_TIMING_3840X2160P_60000, HDMI_VIDEO_PROGRESSIVE,	(HI_U8 *)"3840*2160p60 64:27"},
};

// 4k mode
HDMI_VIDEO_4K_DEF_S s_stH14bHdmiVideoCodes_4K[CEA861FVideoCodesMax_4k] = 
{
    {1, HDMI_3840X2160P30_16_9,     296703, 30, 3840,  2160, HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_30000, HDMI_VIDEO_PROGRESSIVE, 		(HI_U8 *)"3840*2160p30 16:9"},
    {2, HDMI_3840X2160P25_16_9,     297000, 25, 3840,  2160, HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_25000, HDMI_VIDEO_PROGRESSIVE, 		(HI_U8 *)"3840*2160p25 16:9"},
    {3, HDMI_3840X2160P24_16_9,     296703, 24, 3840,  2160, HDMI_PICTURE_ASPECT_16_9, HDMI_VIDEO_TIMING_3840X2160P_24000, HDMI_VIDEO_PROGRESSIVE, 		(HI_U8 *)"3840*2160p24 16:9"},
    {4, HDMI_4096X2160P24_256_135,  297000, 24, 4096,  2160, HDMI_PICTURE_ASPECT_256_135, HDMI_VIDEO_TIMING_4096X2160P_24000, HDMI_VIDEO_PROGRESSIVE, 	(HI_U8 *)"4096*2160p24 256:135"},

};



/*
** Des: vic search
**
*/
HDMI_VIDEO_CODE_E DRV_HDMI_VicSearch(HDMI_VIDEO_TIMING_E enTimming, HDMI_PICTURE_ASPECT enAspect, HI_BOOL b3DEnable)
{
    HI_U32 i = 0, u32VICSize = 0;
    HDMI_VIDEO_DEF_S *pstVideoId = &s_stCEA861FVideoCodesDes[0];
    HDMI_VIDEO_CODE_E enVic = 0;

    u32VICSize = sizeof(s_stCEA861FVideoCodesDes)/sizeof(s_stCEA861FVideoCodesDes[0]);

    for (i = 0; i < u32VICSize; i++, pstVideoId++)
    {
        if (enTimming == pstVideoId->enTiming && enAspect == pstVideoId->enAspectRatio)
        {
            enVic = pstVideoId->enVideoCode;
            break;
        }
    }

    if(HI_TRUE == b3DEnable)
    {
        // VIC = 0 when the timing is HDMI_3840X2160P24_16_9, HDMI_3840X2160P25_16_9, 
        // HDMI_3840X2160P30_16_9, HDMI_4096X2160P24_256_135 at 2D mode
        if(enVic == HDMI_3840X2160P24_16_9 || enVic == HDMI_3840X2160P25_16_9 || 
           enVic == HDMI_3840X2160P30_16_9 || enVic == HDMI_4096X2160P24_256_135)
        {
            HDMI_INFO("AVI infoframe pack: 4k x 2k 2D vic:%d \n", enVic);
            enVic = 0;
        }
    }

    return enVic;
}



HDMI_VIDEO_DEF_S *DRV_HDMI_CommFormatParamGet(HDMI_VIC_E enVic)
{
    HI_U32              i = 0;
    HDMI_VIDEO_DEF_S    *pstTmpFmt= HI_NULL;

    for (i = 0,pstTmpFmt=&s_stCEA861FVideoCodesDes[0];
         i < HDMI_ARRAY_SIZE(s_stCEA861FVideoCodesDes);
         i++,pstTmpFmt++)
    {
        if (pstTmpFmt->enVideoCode == enVic )
        {
            return pstTmpFmt;
        }
    }
    HDMI_WARN("not support vic=%u\n",enVic);
    return HI_NULL;
}




HDMI_VIDEO_TIMING_E DRV_HDMI_VideoTimingSearch(HDMI_VIDEO_CODE_E enVic)
{
    HDMI_VIDEO_TIMING_E enVideoTiming = 0;
    HDMI_VIDEO_TIMING_E vicIndex = 0;

    CHECK_MAX_VALUE(vicIndex, enVic, HDMI_3840X2160P60_64_27);
    enVideoTiming = s_stCEA861FVideoCodesDes[vicIndex].enTiming;

    return enVideoTiming;
}

HDMI_PICTURE_ASPECT DRV_HDMI_AspectRatioSearch(HDMI_VIDEO_CODE_E enVic)
{
    HDMI_PICTURE_ASPECT enVideoAspectRatio = 0;
    HDMI_VIDEO_TIMING_E vicIndex = 0;

    CHECK_MAX_VALUE(vicIndex, enVic, HDMI_3840X2160P60_64_27);
    enVideoAspectRatio = s_stCEA861FVideoCodesDes[vicIndex].enAspectRatio;

    return enVideoAspectRatio;
}

HI_VOID HdmiRegWrite(volatile HI_VOID *pRegAddr, HI_U32 value)
{
    *(volatile HI_U32*)pRegAddr = value;
}

HI_U32 HdmiRegRead(volatile HI_VOID *pRegAddr)
{
    return *(volatile HI_U32*)pRegAddr;
}

/** delay xx ms
**/
HI_VOID DRV_HDMI_MilliDelay(HI_U32 mSec)
{
#ifndef HDMI_BUILD_IN_BOOT
    msleep(mSec);
#else
    udelay(mSec * 1000);
#endif
}
